<template>
  <el-dialog
    title="预约详情"
    :visible.sync="visible"
    width="60%"
    append-to-body
  >
    <avue-form
      ref="addForm"
      v-model="form"
      :option="tableOption"
    >

    </avue-form>
    <div class="hobby mb-20">
      养宠偏好信息：
    </div>
    <div class="mb-20 flex prefer">
      <span
        v-for="(v, k) in form.preferProperties"
        :key="k"
        class="tags-item"
      >{{ v }}</span>
    </div>
    <div class="hobby mb-20">
      想要知道的其他信息：
    </div>
    <div>
      {{ form.content }}
    </div>
  </el-dialog>
</template>

<script>
import { mapGetters } from 'vuex';
import { tableOption } from '@/const/crud/pet/appointmentDetail';
import { getAppointDetailById } from '@/api/core/appointment';
import { getObj } from '@/api/core/pet-file';
export default {
  name: 'appointmentPopup',
  props: {
    id: {
      type: [Object, String],
    },
    value: {
      type: Boolean,
      default: false,
    },
    petId: {
      type: [Object, String],
    },
  },
  data() {
    return {
      form: {},
      loading: false,
      tableOption: tableOption(),
      petForm: {},
    };
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
    ...mapGetters(['userInfo', 'access_token']),
  },
  watch: {
    async visible(val) {
      if (val) {
        await this.getPetDetail();
        await this.getDetail();
        this.form = Object.assign({}, this.form, this.petForm);
      } else {
        this.$refs.addForm && this.$refs.addForm.resetForm();
      }
    },
  },
  methods: {
    async getDetail() {
      const res = await getAppointDetailById(this.id);
      this.form = { ...res.data.data };
      this.form.userNickName = this.form.nickName;
    },
    async getPetDetail() {
      const res = await getObj(this.petId);
      this.petForm = { ...res.data.data };
      this.petForm.personality = JSON.parse(this.petForm.personality)
        .map((el) => el.value)
        .join('、');
    },
  },
};
</script>

<style lang='scss' scoped>
.tags-item {
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid rgba(161, 216, 230, 1);
  color: rgba(161, 216, 230, 1);
  margin-right: 20px;
  margin-bottom: 15px;
}
.mb-20 {
  margin-bottom: 20px;
}
.tags-title {
  width: 80px;
  text-align: right;
}
.prefer {
  flex-wrap: wrap;
}
</style>
